package cn.elves.model.draw.service.impl;

import cn.elves.model.activity.entity.po.UserTakeActivity;
import cn.elves.model.activity.service.ActivityService;
import cn.elves.model.draw.entity.dto.DrawDTO;
import cn.elves.model.draw.service.DrawService;
import cn.elves.model.draw.service.algorithm.DrawInstanceHolder;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DrawServiceImpl implements DrawService {



    @Resource
    private ActivityService activityService;

    @Resource
    private DrawInstanceHolder drawInstanceHolder;

    @Override
    public Long doDraw(DrawDTO drawDTO) {
        //拿到用户参与活动凭证

        UserTakeActivity userTakeActivity = activityService.queryActivityOrJoinActivityIfEffective(drawDTO.getUserId(), drawDTO.getActivityId(),drawDTO.getMatter());

        //利用凭证进行抽奖 选定抽奖策略
        String awardId = drawInstanceHolder.selectDrawStrategyToDraw(userTakeActivity);
        if(StringUtils.isBlank(awardId)){
            return null;
        }

        return Long.parseLong(awardId);
    }
}
